<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <META http-equiv="content-type" content="text/html; charset=utf-8">
    <title>Title</title>
</head>
<body>
<textarea id="createOrder" cols="100" rows="28">{"mobile":"13925126516","token":"123456789"}</textarea><br/>
<input type="text" id="token"  value="j0kpkzlk_523kqbvpqlss58d23613a28b8" style="width:300px;"/>
<input type="text" id="url"  value="{:URL('api/Connect/auth')}" style="width: 300px;"/>
<button id="create" >POST 请求</button>　　　　</br>
<br/>
<input type="file" id="newId" value="">
&deg;&middot;&amp;&lsquo;&rsquo;&sup2;&sup1;&amp;
<br/>
</body>
</html>
<script type="text/javascript" src="/static/admin/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
    $(function(){
        $("#create").on('click',function(){
            var json = $('#createOrder').val();
            var url = $('#url').val();
            json = $.parseJSON(json);
            $.ajax({
                type:'post',
                url:url,
                data:json,
                dataType:'json',
                beforeSend: function(request) {
                    request.setRequestHeader("time", "1456817459");
                    request.setRequestHeader("sign", "196b4e4021967e7b045e6ce30c20a5295467aa1e");
                    request.setRequestHeader("token", $('#token').val());
                    request.setRequestHeader("lang", "zh-cn");
                    request.setRequestHeader("version", "2.0.2");
                },
                success:function(ret,status){
                    console.log(ret);
                    console.log(typeof ret);
                }
            })

        });

        $("#file").on('click',function(){
            var json = $('#createOrder').val();
            var url = $('#url').val();
            json = $.parseJSON(json);
            $.ajax({
                type:'post',
                url:'{:URL("file_send")}',
                data:{"body":json,"url":url},
                dataType:'json',
                success:function(ret,status){
                    console.log(ret);
                    console.log(typeof ret);
                }
            })

        });

        $('#newId').on('change',function(){
            var url = $('#url').val();
            var formdata = new FormData();
            var fileObj = $(this).context.files;
            var len = fileObj.length;
            if( 0 == len ) {
                api.alert({title:'提示',msg:'请选择图片'});
                return false;
            }
            formdata.append('file', fileObj[0]);
            jQuery.ajax({
                beforeSend: function(request) {
                    request.setRequestHeader("time", "1456817459");
                    request.setRequestHeader("sign", "196b4e4021967e7b045e6ce30c20a5295467aa1e");
                    request.setRequestHeader("token", $('#token').val());
                    request.setRequestHeader("lang", "zh-cn");
                    request.setRequestHeader("version", "2.0.2");
                },
                url:url,
                type:'post',
                data:formdata,
                cache:false,
                contentType:false,
                processData:false,
                dataType:"json",
                success:function(ret) {
                    console.log(ret);
                }
            });
        });
    });

</script>